import React from 'react';
import { connect } from 'dva';
import QueueAnim from 'rc-queue-anim';
import { Layout, Row, Col, Card, Spin, Menu, Dropdown, Icon, DatePicker, Badge, Tabs } from 'antd';
import PropTypes from 'prop-types';
import styles from './WeChat.less';
import { LineChart, PieChart, MyChart, MyStep, CityChart, CardMsg, EcharsLine } from '../../components';
import { routerRedux } from 'dva/router';
import moment from 'moment';
import { wx, mytime } from '../../utils/config';
import WechaMenu from './WechaMenu';
import Banner from './BannerAnim';

const { Header, Sider, Content } = Layout;
const day = new Date();
day.setTime(day.getTime() - 24 * 60 * 60 * 1000);
const lastday = `${day.getFullYear()}-${day.getMonth() + 1}-${day.getDate()}`;
const TabPane = Tabs.TabPane;
const arr = [];
for (const i in wx) {
  arr.push(wx[i]);
}
class WeChat extends React.Component {
  constructor(...args) {
    super(...args);
    this.state = {
      mykey: 'Happylife',
      title: '萌岛乐生活',
      visible: false,
      today: lastday,
      UserSummarySum: {},
      UserSummary: {},
      UserCumulate: {},
      UserShareSum: {},
      UpStreamMsgSum: {},
    };
  }
  // 选择日期
  componentWillReceiveProps({ weChat }) {
    console.log('weChat');
    console.log(weChat);
    const { UserSummarySum, UserSummary, UserCumulate, UserShareSum, UpStreamMsgSum } = weChat;
    this.setState({
      UserSummarySum,
      UserSummary,
      UserCumulate,
      UserShareSum,
      UpStreamMsgSum,
    });
    // this.setState({
    //   UserSummarySum,
    //   UserSummary,
    //   UserCumulate,
    //   UserShareSum,
    //   UpStreamMsgSum,
    // });
  }
  onChange = (date, dateString) => {
    this.props.dispatch(routerRedux.push({
      pathname: '/weChat',
      query: { dateString },
    }));
  }


  // 禁止日期
  disabledDate = (current) => {
    // Can not select days before today and today
    return current && current.valueOf() > Date.now() - 1000 * 60 * 60 * 24;
  }

  handleClick = (e) => {
    let title;
    for (let i = 0; i < arr.length; i++) {
      switch (e.key) {
        case arr[i].type: title = arr[i].name;
          break;
      }
    }
    // switch (e.key) {
    //   case 'DimensionCode': title = '维码器商户平台';
    //     break;
    //   case 'Happylife': title = '萌岛乐生活';
    //     break;
    //   case 'Union': title = '萌岛联萌';
    // }
    this.setState({
      mykey: e.key,
      title,
    });
  }
  handleVisibleChange = (flag) => {
    this.setState({ visible: flag });
  }

  render() {
    const { current, UserSummarySum, UserSummary, UserCumulate, UserShareSum, UpStreamMsgSum } = this.state;
    const menuPorps = {
      handleClick: this.handleClick,
      title,
    };
    const title = this.state.title;

    return (
      <div>
        <Layout>
          <Header className={styles.header}>
            <Row gutter={2}>
              <Col span={5}>
                <DatePicker
                  format="YYYY-MM-DD"
                  className={styles.dateStyle}
                  onChange={this.onChange}
                  // showToday={true}
                  defaultValue={moment(this.state.today, 'YYYY-MM-DD')}
                  disabledDate={() => this.disabledDate()}
                />
              </Col>
              <Col span={18}>

                <WechaMenu {...menuPorps} />
              </Col>
            </Row >
          </Header>
          <Layout>
            <Banner />
          </Layout>
        </Layout>
      </div>
    );
  }
}


WeChat.propTypes = {
};


export default connect(({ weChat }) => ({ weChat }))(WeChat);
